package com.starsea.book.ui.newpage.adapter

import android.content.Context
import android.view.ViewGroup
import android.widget.ImageView
import com.starsea.book.base.adapter.ItemViewHolder
import com.starsea.book.base.adapter.RecyclerAdapter
import com.starsea.book.databinding.ItemShowImgBinding
import com.starsea.book.ui.newpage.utils.loadNormalImage
import com.starsea.book.ui.widget.recycler.ItemTouchCallback

/**
 * @author Lee
 * @createTime 2023-08-02 15 GMT+8
 * @desc :
 */
class ImageShowAdapter(
    var mContext: Context,
    var onChanged: ((value: String, position: Int, view: ImageView) -> Unit)? = null
) :
    RecyclerAdapter<String, ItemShowImgBinding>(mContext),
    ItemTouchCallback.Callback {
    override fun getViewBinding(parent: ViewGroup): ItemShowImgBinding {
        return ItemShowImgBinding.inflate(inflater, parent, false)
    }

    override fun registerListener(holder: ItemViewHolder, binding: ItemShowImgBinding) {

        binding.ivImage.setOnClickListener {
            getItem(position = holder.layoutPosition).let {
                onChanged!!.invoke(it!!, holder.layoutPosition, binding.ivImage)
            }
        }

    }

    override fun convert(
        holder: ItemViewHolder,
        binding: ItemShowImgBinding,
        item: String,
        payloads: MutableList<Any>
    ) {
        binding.run { ivImage.loadNormalImage(mContext, item) }
    }


}